package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.ParkingOwnerRelBiz;
import guda.stark.dal.dao.ParkingOwnerRelDAO;
import guda.stark.dal.dataobject.ParkingOwnerRelDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class ParkingOwnerRelBizImpl implements ParkingOwnerRelBiz{

    private final static Logger logger = LoggerFactory.getLogger(ParkingOwnerRelBizImpl.class);

    @Autowired
    private ParkingOwnerRelDAO parkingOwnerRelDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            ParkingOwnerRelDO parkingOwnerRelDO = parkingOwnerRelDAO.getParkingOwnerRelById(id);
            bizResult.data.put("parkingOwnerRelDO", parkingOwnerRelDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query ParkingOwnerRel error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = parkingOwnerRelDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<ParkingOwnerRelDO> parkingOwnerRelList = parkingOwnerRelDAO.selectForPage(baseQuery);
            bizResult.data.put("parkingOwnerRelList", parkingOwnerRelList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view ParkingOwnerRel list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            parkingOwnerRelDAO.delParkingOwnerRelById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete parkingOwnerRel error", e);
        }
        return bizResult;
    }

    public BizResult create(ParkingOwnerRelDO parkingOwnerRelDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = parkingOwnerRelDAO.insert(parkingOwnerRelDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create ParkingOwnerRel error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(ParkingOwnerRelDO parkingOwnerRelDO) {
        BizResult bizResult = new BizResult();
        try {
            parkingOwnerRelDAO.updateByIdSelective(parkingOwnerRelDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update ParkingOwnerRel error", e);
        }
        return bizResult;
    }


}
